﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;

public partial class User_SearchByPrice : System.Web.UI.Page
{
    DataTable tbSearch = new DataTable();
    BouquetBUS bouBUS = new BouquetBUS();
    DataView viewSearch;
    ShoppingCartBUS cartBUS = new ShoppingCartBUS();
    DataView mainTable;
    protected void Page_Load(object sender, EventArgs e)
    {

        LoadData();

    }
    private void LoadData()
    {
        tbSearch = bouBUS.returnAllBouquet();
        viewSearch = new DataView(tbSearch);
        string id = Request.QueryString["id"].ToString();
        switch (id)
        {
            case "1":
                viewSearch.RowFilter = "B_Price<=70";
                break;
            case "2":
                viewSearch.RowFilter = "B_Price>70 AND B_Price<=80";
                break;
            case "3":
                viewSearch.RowFilter = "B_Price>80 AND B_Price<=100";
                break;
            case "4":
                viewSearch.RowFilter = "B_Price>100";
                break;
        }
        mainTable = viewSearch;
        CollectionPager1.MaxPages = 100;
        CollectionPager1.PageSize = 9; // số items hiển thị trên một trang
        CollectionPager1.DataSource = mainTable;
        CollectionPager1.BindToControl = dlSearch;
        dlSearch.DataSource = CollectionPager1.DataSourcePaged;
        dlSearch.DataBind();

        //dlSearch.DataSource = viewSearch;
        //dlSearch.DataBind();
    }
    protected void dlSearch_ItemCommand(object source, DataListCommandEventArgs e)
    {
        if (e.CommandName.Equals("AddCart"))
        {
            cartBUS.Add(e.CommandArgument.ToString(), 1);
            Response.Redirect("ShoppingCart.aspx");
        }
    }
}